package com.sskj.award.ui.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.sskj.award.R;
import com.sskj.award.R2;
import com.sskj.award.bean.SuperAbonusBean;
import com.sskj.award.presenter.SuperAbonusRecordPresenter;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.adapter.BaseAdapter;
import com.sskj.lib.adapter.ViewHolder;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.util.NumberUtil;

import java.util.List;

import butterknife.BindView;

/**超级平台分红记录
 * @author Hey
 * Create at  2019/07/18
 */
@Route(path = RConfig.SUPER_SUPER_ABONUS_RECORD_DROP)
public class SuperAbonusRecordActivity extends BaseActivity<SuperAbonusRecordPresenter> {

    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.rvABonus)
    RecyclerView rvABonus;
    @BindView(R2.id.srlABonus)
    SmartRefreshLayout srlABonus;
    private BaseAdapter<SuperAbonusBean.DataBean> adapter;

    @Override
    public int getLayoutId() {
        return R.layout.super_activity_super_abonu_srecord;
    }

    @Override
    public SuperAbonusRecordPresenter getPresenter() {
        return new SuperAbonusRecordPresenter();
    }

    @Override
    public void initView() {
        tvTitle.setText(App.INSTANCE.getString(R.string.super_devidends_record));

        rvABonus.setLayoutManager(new LinearLayoutManager(this));
        rvABonus.addItemDecoration(new DividerLineItemDecoration(this)
                .setLeftPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 1))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.super_divi_split))
        );
    }

    @Override
    public void initData() {
        mPresenter.getABonusData();
    }

    public void getABonusSuccess(SuperAbonusBean data) {
        if (data==null){
            return;
        }
        List<SuperAbonusBean.DataBean> data1 = data.getData();
        adapter=new BaseAdapter<SuperAbonusBean.DataBean>(R.layout.super_abonus_item,null,rvABonus,true) {
            @Override
            public void bind(ViewHolder holder, SuperAbonusBean.DataBean item) {
                holder.setText(R.id.tvMoney, NumberUtil.keepNoZero(NumberUtil.keep(item.getMoney(),6))+"USDT");
                holder.setText(R.id.tvTime,item.getCreated_at());
            }
        };
        adapter.addData(data1);
    }

    public void onStopFresh() {
        if (srlABonus!=null){
            srlABonus.finishLoadMore();
            srlABonus.finishRefresh();
        }
    }
}
